package org.example.login;

import javax.imageio.ImageIO;
import javax.swing.*;
import java.awt.*;
import java.io.File;
import java.io.IOException;

/**
 * @author :Mr.zhou
 * @description: TODO edit class Description
 * @create date: 2025/2/21 21:52
 */
public class LoginPenal extends JPanel {

    String backgroud;

    public LoginPenal(String backgroud) {
        this.backgroud=backgroud;
    }

    @Override
    protected void paintComponent(Graphics g) {
        super.paintComponent(g);
        try {
            Image  originalImage = ImageIO.read(new File(LoginPenal.class.getResource(backgroud).getPath()));
            int panelWidth = getWidth();
            int panelHeight = getHeight();
            Image scaledImage = originalImage.getScaledInstance(
                    panelWidth, panelHeight, Image.SCALE_SMOOTH
            );
            g.drawImage(scaledImage, 0, 0, this);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }

        /*ImageIcon icon = new ImageIcon(LoginPenal.class.getResource(backgroud).getPath());
        Image img = icon.getImage();
        g.drawImage(img, 0, 0, this.getWidth(), this.getHeight(), null);*/
    }
}
